package com.jh3502.vivo.function.contact;

import android.support.annotation.NonNull;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jh3502.vivo.base.BaseCallback;
import com.jh3502.vivo.base.BaseJson;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.base.BaseView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class ContactPresenter extends BasePresenter<ContactPresenter.ContactView> {
    ContactModel mContactModel;

    ContactView mContactView;


    public void setContactView(ContactView mContactView) {
        this.mContactView = mContactView;

    }

    public void toGetorganization(Map<String, Object> body) {
        mContactView.showLoadingDialog();
        if (mContactModel == null) {
            mContactModel = new ContactModel(mContactView.getActContext());
        }

        mContactModel.getorganization(body, new BaseCallback(mContactView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mContactView.getorganizationSuccess(baseJson.getObj().toString());
            }
        });
    }


    public void toFindEntrustUsers() {
        mContactView.showLoadingDialog();
        if (mContactModel == null) {
            mContactModel = new ContactModel(mContactView.getActContext());
        }

        mContactModel.findEntrustUsers(new BaseCallback(mContactView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mContactView.getorganizationSuccess(baseJson.getObj().toString());
            }
        });
    }

    @Override
    public void cancelCall() {

    }

    public interface ContactView extends BaseView {

        void getorganizationSuccess(String s);

    }

    public ArrayList<ContactBean> getContact(String s) {
        return new Gson().fromJson(s,
                new TypeToken<List<ContactBean>>() {
                }.getType());
    }
}
